package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.getCurrencyBean;
import com.ymatou.iapi.godmch.parameter.getCurrencyResp;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.getCurrencyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.country_info;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.sqlwapper.godmch.country_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
/**
*获取商户币种
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getCurrency{
	private static getCurrencyBean bean;
	private static getCurrencyCall call;
	mch_infoWapper mchinfoWapper=new mch_infoWapper();
	country_infoWapper countryWapper=new country_infoWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商户币种");
	}

	@Before
	public void caseUp() {
		bean=new getCurrencyBean();
		call=new getCurrencyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void check_verify() throws InterruptedException
	{
		HashMap<String,Object> map=new HashMap();
		map.put("mchId", bean.getMchId());
		mch_info p_mch= mchinfoWapper.selectby(map).get(0);
		getCurrencyResp resp=call.getCurrencyResp();
		Logger.verifyEquals("200", call.getStatus1(), "验证status");
		Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
		if(resp.getCurrencyList().size()>0){
			//第一个币种是人民币
			Logger.verifyEquals(resp.getCurrencyList().get(0).getCurrency(), "CNY", "验证第一条数据的Currency");
			Logger.verifyEquals(resp.getCurrencyList().get(0).getCurrencyName(), "人民币", "验证第一条数据的CurrencyName");
			Logger.verifyEquals(resp.getCurrencyList().get(0).getCurrencySymbol(), "¥", "验证第一条数据的CurrencySymbol");
			Logger.verifyEquals(resp.getCurrencyList().get(0).getExchangeRate().stripTrailingZeros().toPlainString(), "1", "验证第一条数据的ExchangeRmbRate");
			
			//第二个币种是当前商户的自己的
			//这几个币种不支持本国币种
			if(!(p_mch.getCurrency().equals("AUD") || p_mch.getCurrency().equals("KRW")|| p_mch.getCurrency().equals("CHF")|| p_mch.getCurrency().equals("NZD")))
			{
				Logger.verifyEquals(resp.getCurrencyList().get(1).getCurrency(), p_mch.getSettlementCurrency(), "验证第二条数据的Currency");
				Logger.verifyNotNull(resp.getCurrencyList().get(1).getCurrencyName(), "验证第二条数据的CurreCurrencyNamencySymbol");
				Logger.verifyNotNull(resp.getCurrencyList().get(1).getCurrencySymbol(), "验证第二条数据的CurrencySymbol");
				Logger.verifyNotNull(resp.getCurrencyList().get(1).getExchangeRate(), "验证第二条数据的ExchangeRmbRate");
				
				Logger.verifyNotNull(resp.getCurrencyList().get(0).getSupportDecimalPlaces(), "验证第一条数据的SupportDecimalPlaces");
				Logger.verifyNotNull(resp.getCurrencyList().get(1).getSupportDecimalPlaces(), "验证第二条数据的SupportDecimalPlaces");
			}
			else
			{
				Logger.verifyEquals("USD", p_mch.getSettlementCurrency(), "验证第二条数据的Currency");
			}
			
			if(!p_mch.getMultiCurrency().equals(""))
			{
				int i=2;
				String[] str=p_mch.getMultiCurrency().split(",");
				
				for(String s: str)
				{
					if(s.equals(p_mch.getSettlementCurrency()) || s.equals("CNY"))
						continue;
					Logger.verifyEquals(resp.getCurrencyList().get(i).getCurrency(), s, "验证第"+(i+1)+"条数据的Currency");
					i++;
				}
			}
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_001() {
		Logger.start(true,"正例-获取商户币种-商户是渠道-普通国家");
		try {
			//渠道用户
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(2,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_002() {
		Logger.start(true,"正例-获取商户币种-商户是渠道-香港");
		try {
			//渠道用户
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			createBean1.setCountry("HKG");
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(2,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_002_2() {
		Logger.start(true,"正例-获取商户币种-商户是渠道-不支持本国币种-也返回当前国家(country_info.supportLocalCurrency=0 表示不支持本国币种,不支持本土mchinfo中的结算币种是USD)");
		try {
			//渠道用户
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			createBean1.setCountry("AUS");
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(2,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_003() {
		Logger.start(true,"正例-获取商户币种-商户是渠道-日本");
		try {
			//渠道用户
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			createBean1.setCountry("JPN");
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(2,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_004() {
		Logger.start(true,"正例-获取商户币种-商户是代理-普通国家");
		try {
			//渠道用户
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			createListBean.get(0).setCountry("USA");
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			bean.setMchId(mchId_agent);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(2,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_005() {
		Logger.start(true,"正例-获取商户币种-商户是代理-香港");
		try {
			//渠道用户
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			createBean1.setCountry("HKG");
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			createListBean.get(0).setCountry("HKG");
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			bean.setMchId(mchId_agent);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(2,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_005_1() {
		Logger.start(true,"正例-获取商户币种-商户是代理-特殊渠道是香港，代理日本");
		try {
			//渠道用户
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
		//	int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			int mchId=500182875;
			usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			createListBean.get(0).setCountry("JPN");
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			bean.setMchId(mchId_agent);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(2,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_005_2() {
		Logger.start(true,"正例-获取商户币种-商户是代理-特殊渠道是香港，代理韩国(特殊商户渠道可以代理任何国家 跨国20191023修改)");
		try {
			//渠道用户
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			//int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			int mchId=500182875;
			usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);

			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			createListBean.get(0).setCountry("KOR");
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			bean.setMchId(mchId_agent);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(2,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_006() {
		Logger.start(false,"正例-获取商户币种-商户Id为空");
		try {
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("500", call.getStatus1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_007() {
		Logger.start(true,"正例-获取商户币种-商户是渠道-普通国家");
		try {
			//渠道用户
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(2,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_008() {
		Logger.start(true,"正例-获取商户币种-商户是渠道-普通国家-创建独立商户");
		try {
			
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall  createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			
			bean.setMchId(createCall.getmchId());
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(2,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_009() {
		Logger.start(true,"正例-获取商户币种-商户是渠道-多标价币种multiCurrency有值");
		try {
			
			bean.setMchId(500860518);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(3,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_010() {
		Logger.start(true,"正例-获取商户币种-商户是渠道-多标价币种multiCurrency有一值");
		try {
			
			bean.setMchId(500860518);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(3,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_011() {
		Logger.start(true,"正例-获取商户币种-商户是渠道-多标价币种multiCurrency有二值");
		try {
			
			bean.setMchId(500860511);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(4,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getCurrency_012() {
		Logger.start(true,"正例-获取商户币种-商户是渠道-结算币种settlementCurrency与多标价币种multiCurrency重复");
		try {
			
			bean.setMchId(500860522);
			call.setData(bean);
			call.callService();	
			getCurrencyResp resp=call.getCurrencyResp();
			Logger.verifyEquals(4,resp.getCurrencyList().size(), "验证返回国家条数");
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}